473,461 Members | 1,426 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Python pack and unpack question

If you have the following:

data = unpack('>L', sock.recv(4))

Does this line of code means that incoming data is big endian and
unpack it to endianess of local machine? If local machine is little
endian, then big endian is automatically converted to little endian
format?

thank you.
Jul 15 '08 #1
1 3132

"joe shoemaker" <jo***********@gmail.comwrote in message
news:ma***********************************@python. org...
If you have the following:

data = unpack('>L', sock.recv(4))

Does this line of code means that incoming data is big endian and
unpack it to endianess of local machine? If local machine is little
endian, then big endian is automatically converted to little endian
format?

thank you.
Try it:
>>data = unpack('>L','\xaa\xbb\xcc\xdd')
data
(2864434397L,)
>>hex(data[0])
'0xaabbccddL'
>>data = unpack('>L','\x11\x22\x33\x44')
data
(287454020,)
>>hex(data[0])
'0x11223344'
>>>
Yes, it treats the incoming data as big-endian. The Python data type
returned varies as needed to hold the value. You'd get the same results on
a big-endian and little-endian local machine. How the Python data type is
represented internally is an implementation detail and could be anything.
--
Mark

Jul 15 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: RK | last post by:
Hi I am new to Python, find it very interesting. I was wondering if anyone has a sample source listing for an nntp newsgroup reader that they can share or will be able to point me to a...
2
by: John Hunter | last post by:
I am writing a python extension and have a question about reference counting on an attribute I set. I am using standard boilerplate code for defining a new type. I implement the setattr...
4
by: Efrat Regev | last post by:
Hello, I'd like to ask a question concerning a python script in a makefile. Suppose I have a C++ project (sorry for raising this in a Python newsgroup), with some makefile for it. Before...
4
by: Stacy Mader | last post by:
Greetings all, I have a VMS binary file with weather data. The record on each line is 1xint(8) 12xint(2) Using the perl unpack function, I can decode the binary file like this: <snip>
1
by: Shi, Jue | last post by:
Hello, Gurus, I have a question on wrapping C function in Python. My C code is like this: typedef void (WINAPI *myCallBack) (unsigned int myarg1, unsigned int myarg2) bool ...
5
by: bruce | last post by:
hi... i'm trying to deal with multi-dimension lists/arrays i'd like to define a multi-dimension string list, and then manipulate the list as i need... primarily to add lists/information to the...
23
by: neoedmund | last post by:
There's a program, it's result is "unexpected aaa", i want it to be "expected aaa". how to make it work? class C1(object): def v(self, o): return "expected "+o class C2(object):
13
by: James | last post by:
Hello, I'm a newbie to Python & wondering someone can help me with this... I have this code: -------------------------- #! /usr/bin/python import sys
5
by: tmp123 | last post by:
Hello, Thanks for your time. After review the "struct" documentation, it seems there are no option to pack/unpack zero terminated strings. By example, if the packed data contains: byte +...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.